import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../utils/screenAdapter.dart';
import '../controllers/goods_details_controller.dart';

class CardItemNumView extends GetView<GoodsDetailsController> {
  const CardItemNumView({super.key});
  Widget _left() {
    // 减法
    return InkWell(
      onTap: () {
        controller.decrementCount(); // 减少数量
      },
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26),
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(ScreenAdapter.radius(40)),
            bottomLeft: Radius.circular(ScreenAdapter.radius(40)),
          ),
        ),
        width: ScreenAdapter.width(80),
        height: ScreenAdapter.height(80),
        child: Center(child: Text('-')),
      ),
    );
  }

  Widget _center() {
    return Container(
      decoration: BoxDecoration(
        border: Border(
          top: BorderSide(color: Colors.black26),
          bottom: BorderSide(color: Colors.black26),
        ),
      ),
      width: ScreenAdapter.width(80),
      height: ScreenAdapter.height(80),
      child: Center(child: Text("${controller.buyCount}")),
    );
  }

  Widget _right() {
    return InkWell(
      onTap: () {
        controller.incrementCount();
      }, // 增加数量
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: Colors.black26),
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(ScreenAdapter.radius(40)),
            bottomRight: Radius.circular(ScreenAdapter.radius(40)),
          ),
        ),
        width: ScreenAdapter.width(80),
        height: ScreenAdapter.height(80),
        child: Center(child: Text('+')),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      child: Obx(() => Row(children: [_left(), _center(), _right()])),
    );
  }
}
